<?php

namespace Biz\Models\Site;

use Biz\Constants\Site\SitePaperConstants;
use Biz\Models\Model;
use Biz\Models\User\User;
use Dimsav\Translatable\Translatable;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * SiteVenue.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class SitePaper extends Model
{
    use SoftDeletes, Translatable;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'site_paper';

    /**
     * @var array
     */
    protected $fillable = [
        'user_id',
        'site_id',
        'theme_id',
        'number',
        'presentation_preference',
        'status',
    ];

    /**
     * Translations.
     */
    public $translationModel      = SitePaperTranslation::class;
    public $translatedAttributes  = ['title', 'remark'];
    public $translationForeignKey = 'paper_id';

    /**
     * 查询用户.
     */
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }

    /**
     * 论文作者列表.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function authors()
    {
        return $this->hasMany(SitePaperAuthor::class, 'paper_id');
    }

    /**
     * 一对一摘要.
     */
    public function abstract()
    {
        return $this->hasOne(SitePaperAbstract::class, 'paper_id', 'id');
    }

    /**
     * 一对一全文.
     */
    public function full()
    {
        return $this->hasOne(SitePaperFull::class, 'paper_id', 'id');
    }

    /**
     * 获取分类.
     */
    public function theme()
    {
        if($this->theme_id === SitePaperConstants::THEME_DEFAULT){
            return null;
        }
        return $this->belongsTo(SitePaperTheme::class, 'theme_id', 'id');
    }
}
